package com.lanou3g.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lanou3g.bean.Clean;
import com.lanou3g.mapper.CleanMapper;
import com.lanou3g.service.CleanService;
import com.lanou3g.util.Result;
@Service
public class CleanServiceImpl implements CleanService {

	@Autowired
	private CleanMapper cleanMapper;
	@Override
	public Result getCleans(Integer page, Integer limit) {
		List<Clean> cleanList = cleanMapper.getCleans();
		PageHelper.startPage(page, limit);
		PageInfo<Clean> pageInfo = new PageInfo<>(cleanList);
		Result result = new Result(0,"获取列表信息成功!");
		result.setCount(pageInfo.getTotal());
		result.setData(pageInfo.getList());
		return result;
	}
	@Override
	public Result insertClean(Clean clean) {
		int rows = cleanMapper.insertClean(clean);
		if(rows == 0) {
			//添加失败
			return new Result(1,"添加清洁记录失败!");
		}else {
			return new Result(0,"添加清洁记录成功!");
		}
	}
	@Override
	public Clean getCleanById(Integer id) {
		return cleanMapper.getCleanById(id);
	}
	@Override
	public Result updateClean(Clean clean) {
		int rows = cleanMapper.updateClean(clean);
		if(rows == 0) {
			//更新失败
			return new Result(1,"更新清洁记录失败!");
		}else {
			return new Result(0,"更新清洁记录成功!");
		}
	}
	@Override
	public Result deleteCleanById(Integer id) {
		int rows = cleanMapper.deleteCleanById(id);
		if(rows == 0) {
			//删除失败
			return new Result(1,"删除清洁记录失败!");
		}else {
			return new Result(0,"删除清洁记录成功!");
		}
	}

}
